package com.wx.gof.pattern.behavioral.observer.pull;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Anchor
 * @Author wx
 * @Description 被观察者对象-主播
 * @Date 2018-12-14-20:56
 */
@Data
public class Anchor implements Observerable {
    private String name;
    private String title;
    private List<Observer> observerList;


    public Anchor(String name,String title) {
        this.name = name;
        this.title = title;
        this.observerList = new ArrayList<>();
    }

    @Override
    public void registerObserver(Observer o) {
        this.observerList.add(o);
    }

    @Override
    public void removeObserver(Observer o) {
        this.observerList.remove(o);
    }

    @Override
    public void notifyObserver() {
    this.observerList.forEach(observer ->{
        observer.update(this);
    });
    }

    @Override
    public void ObserverableInfo() {
        System.out.println("主播姓名:" + this.name + "--直播内容:" + this.title);
    }
}
